<?php

abstract class AbstractGenericDao {

	/**
	 * Single PDO instance.
	 *
	 * @var PDO
	 */
	private $db;
	
	/**
	 * Single constructor.
	 *
	 * @param PDO $db
	 * @return AbstractGenericDao
	 */
	public function AbstractGenericDao($db) {
		$this->db = $db;
	}
	
	/**
	 * Delegate method.
	 *
	 * @param String $sql
	 * @return PDOStatement
	 */
	protected final function prepareStatement($sql) {
		return $this->db->prepare($sql);
	}
	
	/**
	 * Delegate method.
	 *
	 * @return int
	 */
	protected final function lastInsertId() {
		return $this->db->lastInsertId();
	}

	/**
	 * Delegate method which fetches data afterwards.
	 *
	 * @param String $sql
	 * @return Object[]
	 */
	protected final function dbQuery($sql) {
		$res = $this->db->query($sql);
		return $res->fetchAll();
	}
	
	/**
	 * Delegate method.
	 *
	 * @param String $sql
	 */
	protected final function dbExec($sql) {
		$this->db->exec($sql);
	}
}

?>